﻿//作者：MrLee
//时间：2011-8-23
//名称：日志管理
Ext.namespace('FantastPlatform', 'FantastPlatform.UI');
FantastPlatform.UI.WorkLogGrid = function (config) {
    Ext.apply(this, config);
    var fileStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '../Service/WorkLog.aspx?Action=Search'

        }),
        reader: new Ext.data.JsonReader({
            root: 'topics',
            totalProperty: 'totalCount',
            id: 'Id',
            fields: ['Id', 'Content', 'PoliceMan', 'IsPrompt', 'PromptTime', 'CreateDate','MessageCount']
        }),
        remoteStore: true
    });
    this.store = fileStore;

    var paperBar = new FantastPlatform.Common.PapeToolBar({
        store: fileStore,
        noSort: true,
        defaultNum: 21
    });
    this.paperBar = paperBar;
    this.bbar = paperBar;
    this.pageNumber = paperBar.pageSize;

    var nm = new Ext.grid.RowNumberer();
    var sm = new Ext.grid.CheckboxSelectionModel();
    function renderLast(value, p, record) {
        if (value == true) {
            return String.format('<font color=red>{0}</font>', '是');
        }
        else {
            return String.format('<font color=blue>{0}</font>', '否');
        }
    };
    this.columns = [nm, sm, {
        header: 'Id',
        dataIndex: 'Id',
        hidden: true
    }
//    , {
//        header: '日志标题',
//        dataIndex: 'Title',
//        sortable: true
//    }
    , {
        header: '日志内容',
        dataIndex: 'Content',
        sortable: true
    }, {
        header: '创建人',
        dataIndex: 'PoliceMan',
        sortable: true
    }, {
        header: '创建时间',
        dataIndex: 'CreateDate',
        sortable: true
    }, {
        header: '是否提示',
        dataIndex: 'IsPrompt',
        sortable: true,
        renderer: renderLast
    }, {
        header: '提示时间',
        dataIndex: 'PromptTime',
        sortable: true
    }, {
        header: '回复次数',
        dataIndex: 'MessageCount',
        sortable: true
    }
    ]

    FantastPlatform.UI.WorkLogGrid.superclass.constructor.call(this, {
        loadMask: { msg: '正在加载数据...' },
        sm: sm
    });
};
Ext.extend(FantastPlatform.UI.WorkLogGrid, Ext.grid.GridPanel, {
    onRender: function (ct, position) {
        FantastPlatform.UI.WorkLogGrid.superclass.onRender.call(this, ct, position);
    },
    //添加
    onAddWorkLogGridClick: function () {
        var id = GUID();
        currtWind = openWind('../Message/WorkLogForm.aspx', id, '发表新日志', 460, 200, 'new_tab')
    },

    //修改
    onEditWorkLogGridClick: function () {
        var node = checkGridSelected(this);
        if (node) {
            if (node.length > 1) {
                showErrorMessage("操作失败", "只能选择一条数据进行编辑", "");
            } else {
                var fId = node[0].get('Id');
                var id = GUID();
                currtWind = openWind('../Message/WorkLogForm.aspx?Id=' + fId, id, '编辑日志', 460, 200, null);
            }
        }
    },

    //删除
    onDeleteWorkLogGridClick: function () {
        var grid = this;
        var node = checkGridSelected(this);
        if (node) {
            Ext.Msg.confirm('提示', '确认要删除选中的数据吗？', function (btn) {
                if (btn == 'yes') {
                    Ext.Msg.wait('正在删除数据，请稍候……', '删除数据');
                    var fIds = getIdFromGrid(node, 'Id');
                    ajaxCalled(null, '../Service/WorkLog.aspx?Action=Delete', fIds, grid, null);
                }

            })
        }
    },
    //查看回复
    onDetailsWorkLogGridClick: function () {
        var node = checkGridSelected(this);
        if (node.length > 1) {
            showErrorMessage("操作失败", "只能选择一条日志进行查看", "");
        } else {
            var fId = node[0].get('Id');
            var id = GUID();
            currtWind = openWind('../Message/WorkReplyPanel.aspx?Id=' + fId, id, '查看日志回复', 450, 420, null);
        }

    },
    //查询
    onSearchClick: function () {
        var id = GUID();
        currtWind = openWind('../Message/WorkLogSearchForm.aspx', id, '查询', 360, 150, 'new_tab');
    },
    //刷新
    onUpdataWorkLogGridClick: function () {
        this.store.removeAll();

        if (type == "Prompt")
            this.store.proxy.conn = { method: 'post', url: this.url };
        else
            this.store.proxy.conn = { method: 'post', url: this.url };

        this.store.load({ params: { start: 0, limit: this.paperBar.getPageNumber(), dir: '', sort: ''} });
    }
});